package com.pri.chat.adapter;

import android.view.View;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.netease.nim.uikit.net.entity.DTBean;
import com.pri.chat.R;
import com.pri.chat.utils.FriendsCircleImageLayout;
import com.pri.chat.utils.GlideUtil;
import com.pri.chat.utils.StringUtils;
import com.pri.chat.utils.TimeUtils;
import com.pri.chat.view.ImageViewPlus;
import com.vondear.rxtool.RxDataTool;

import java.util.List;

/**
 * 描述：添加类的描述
 *
 * @author wx5e48d604c2885118
 * @time 2020/4/7
 */
public class DTAdapter extends BaseQuickAdapter<DTBean, BaseViewHolder> {
    private OnImageClickListener mOnImageClickListener;
    public void setOnImageClickListener( OnImageClickListener listener) {
        mOnImageClickListener = listener;
    }
    public interface OnImageClickListener {

        void onItemClick(View view, int c_pos,int f_pos);
    }

    public DTAdapter(int layoutResId, @Nullable List<DTBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, DTBean item) {
        helper.addOnClickListener(R.id.iv_logo);
        helper.addOnClickListener(R.id.zanLinear);
        helper.addOnClickListener(R.id.tv_say_hello);
        helper.addOnClickListener(R.id.iv_share);
        ImageView zanLogo = helper.getView(R.id.zanLogo);
        if(item.getSfdz()==0){
            zanLogo.setImageResource(R.mipmap.ic_zan_gray_normal);
        }else {
            zanLogo.setImageResource(R.mipmap.ic_zan_selected);
        }
        helper.setText(R.id.tv_dt_age,item.getAge());
        helper.setText(R.id.tv_dt_name,item.getMemberName());
        helper.setText(R.id.tv_dt_desc,item.getContent());
        if(item.getSfdc() == 1){
            helper.setBackgroundRes(R.id.tv_say_hello,R.drawable.btn_gray30_shape);
        }else{
            helper.setBackgroundRes(R.id.tv_say_hello,R.drawable.btn_orange_gradient_shape);
        }

        View sexLinear = helper.getView(R.id.sex_bg);
        ImageView sexLogo = helper.getView(R.id.sex_logo);
        if(item != null && "男".equals(item.getSex())){
            sexLogo.setImageResource(R.mipmap.man);
            sexLinear.setBackgroundResource(R.drawable.btn_sex_man);
        }else{
            sexLogo.setImageResource(R.mipmap.woman);

            sexLinear.setBackgroundResource(R.drawable.btn_sex_woman);
        }
        TextView vip_bg = helper.getView(R.id.vip_bg);
        if("是".equals(item.getMemberLevel())){
            vip_bg.setText("VIP");
            vip_bg.setVisibility(View.VISIBLE);
        }else{
            vip_bg.setVisibility(View.GONE);
        }
        TextView vip_super_bg = helper.getView(R.id.vip_super_bg);
        if("是".equals(item.getSuperVip())){
            vip_super_bg.setText("SVIP");
            vip_super_bg.setVisibility(View.VISIBLE);
        }else{
            vip_super_bg.setVisibility(View.GONE);
        }

        String info = TimeUtils.computeFromNowStr(item.getAddDate());
        TextView time_address_look = helper.getView(R.id.time_address_look);
        if(!StringUtils.isEmpty(item.getCity())){
            info += " · "+item.getCity();
        }
        info += " · "+item.getReadNum()+"人看过";
        time_address_look.setText(info);

        GlideUtil.getInstance().loadHeadImg(mContext,(ImageViewPlus)helper.getView(R.id.iv_logo),item.getHeadPic());
        helper.setText(R.id.zanNum,item.getZanNum()+"");
//        helper.setText(R.id.tv_dt_coll,item.getName());
        helper.setText(R.id.plNum,item.getPlNum());
        if(!RxDataTool.isEmpty(item.getPicList())){
            ((FriendsCircleImageLayout)helper.getView(R.id.circle_layout)).setImageUrls(item.getImgs());
            ((FriendsCircleImageLayout)helper.getView(R.id.circle_layout)).setSpacing(10f);
            ((FriendsCircleImageLayout)helper.getView(R.id.circle_layout)).setOnItemClickListener(new FriendsCircleImageLayout.OnItemClickListener() {
                @Override
                public void onItemClick(View view, int position) {
                    mOnImageClickListener.onItemClick(view,position,helper.getAdapterPosition());
                }
            });
            helper.getView(R.id.circle_layout).setVisibility(View.VISIBLE);
        }else{
            helper.getView(R.id.circle_layout).setVisibility(View.GONE);
        }
    }
}
